package com.hyt.it.ogt.kq.service.gov.schedule.impl.support;

import java.util.BitSet;
import java.util.List;

import com.hyt.it.ogt.kq.service.gov.schedule.model.Candidate;
import com.hyt.it.ogt.kq.service.gov.schedule.strategy.ScheduleHelper;

import lombok.Data;

@Data
public class CandidateGroup {
    public String groupName;
    public String batchNo;
    public List<Candidate> candidates;
    public int candidateNumber;
    // 分组考生特征码：考生索引号的组合
    private BitSet featureCode;

    public CandidateGroup(String batchNo, String groupName, int candidateNumber, BitSet featrueCode) {
        this.batchNo = batchNo;
        this.groupName = groupName;
        this.candidateNumber = candidateNumber;
        this.featureCode = featrueCode;
    }

    public CandidateGroup(String batchNO, String groupName, List<Candidate> candidates, int totalCandidateNumber) {
        this.batchNo = batchNO;
        this.groupName = groupName;
        this.candidates = candidates;
        this.candidateNumber = this.candidates.size();
        this.featureCode = new BitSet(totalCandidateNumber);
        this.initFeatureCode();
    }

    public void increamentCandidatesNumber() {
        this.candidateNumber = this.candidates.size();
    }

    private void initFeatureCode() {
        // 考生组的特征码，所有考生的特征码相加
        this.candidates.forEach(item -> {
            this.featureCode
                    .set(ScheduleHelper.getInstance().getCandidate2IndexMap().get(item.getBmStudentId()));
        });
    }

    /**
     * 返回组内学生的ID号
     * 
     * @return
     */
    public String featureCodeStr() {
        return this.featureCode.toString().replace("{", "").replace("}", "");
    }

}
